Be careful with one-line declarations such as the following:
Dim intTemp, intCount As Integer
In this code, the variable intTemp is not actually given a data type. You may think that because theres an As Integer at the end of the line that both variables are declared as an integer type. However, the first variable, intTemp, is actually an untyped variable. A default data type is given to any untyped variable: the Variant data type. Youll learn about variants later in this chapter. If you want to make both of the variables an integer data type, you would change the code to read as follows:
Dim intTemp As Integer, intCount As Integer
To make your code more readable, you should strive to put each variable declaration on a separate line. This not only looks better but it allows you to put a comment next to each variable describing what that variable does. Heres an example:
Dim intTemp As Integer
Dim intCount As Integer
Assigning Values to Variables
The equal sign (=) is used to assign a value to a variable you declare. You cannot declare a variable and assign a value to it all in one statement. You must put the assignment on a separate line. Heres some code showing the different data types and how to assign values to them:
Dim boolOK As Boolean
Dim bytValue As Byte
Dim dtBegin As Date
Dim dtTime As Date
Dim intLoop As Integer
Dim lngID As Long
Dim sngQty As Single
Dim dblAmount As Double
Dim curPrice As Currency
Dim strName As String